/**
 * @file   1107.cpp
 * @author Shuang Hu <hsmath@ubuntu>
 * @date   Sun May  9 23:27:24 2021
 * 
 * @brief  PAT 1107:BFS
 * 
 * 
 */
#include<queue>
#include<map>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
bool cmp(int a,int b){
    return a>b;
}
class Graph{
private:
    map<int,vector<int>> PtoH;//people to hobby
    map<int,vector<int>> HtoP;//hobby to people
    map<int,bool> visitedP;//People is visited or not
    map<int,bool> visitedH;//Hobby is visited or not
    int peoplenum;
    int clusternum;
    vector<int> cluster;
public:
    Graph();
    void BFS();//Broad-First Search
    void broadfirstsearch(int Node);//The achievement of BFS
    void print(){
	sort(cluster.begin(),cluster.end(),cmp);
	cout<<clusternum<<endl;
	cout<<cluster[0];
	for(int i=1;i<clusternum;i++){
	    cout<<" "<<cluster[i];
	}
	cout<<endl;
    }
};
Graph::Graph(){
    cin>>peoplenum;
    for(int i=1;i<=peoplenum;i++){
	visitedP[i]=false;
	int hobbynum;
	char c;
	cin>>hobbynum>>c;
	for(int j=0;j<hobbynum;j++){
	    int hobby;
	    cin>>hobby;
	    PtoH[i].push_back(hobby);
	    HtoP[hobby].push_back(i);
	    visitedH[hobby]=false;
	}
    }
    clusternum=0;
}
void Graph::BFS(){
    for(int i=1;i<=peoplenum;i++){
	if(visitedP[i]==false){
	    broadfirstsearch(i);
	    clusternum++;
	}
    }
}
void Graph::broadfirstsearch(int Node){
    queue<int> people;
    queue<int> hobby;
    people.push(Node);
    int num=0;
    while(people.empty()==false||hobby.empty()==false){
	while(people.empty()==false){
	    int p=people.front();
	    people.pop();
	    num++;
	    visitedP[p]=true;//p has been traversed
	    for(int i=0;i<PtoH[p].size();i++){
		if(visitedH[PtoH[p][i]]==false){
		    hobby.push(PtoH[p][i]);
		}
	    }
	}
	while(hobby.empty()==false){
	    int h=hobby.front();
	    hobby.pop();
	    visitedH[h]=true;
	    for(int i=0;i<HtoP[h].size();i++){
		if(visitedP[HtoP[h][i]]==false){
		    people.push(HtoP[h][i]);
		}
	    }
	}
    }
    cluster.push_back(num);
}
int main(){
    Graph G;
    G.BFS();
    G.print();
}
